package Test;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author 徐志荣
 * @date 2023/4/17 20:35
 */
public class StudentDel {
    public static void main(String[] args) throws SQLException {
        Scanner scanner = new Scanner(System.in);

        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/test4?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("123456");

        Connection connection =  dataSource.getConnection();

        System.out.println("请输入学生姓名:");
        String name = scanner.next();

        String sql = "delete from student where stuName = ?;";

        PreparedStatement statement = connection.prepareStatement(sql);

        statement.setString(1,name);

        System.out.println(statement);

        int ret = statement.executeUpdate();
        System.out.println("ret = " + ret);
        statement.close();
        connection.close();
    }
}
